home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2000 July / CD 3 / redhat-6.2.iso / RedHat / instimage / usr / lib / anaconda / textw / packages.py < prev    next >
Encoding:
Python Source  |  2000-03-08  |  5.1 KB  |  157 lines

  1. import rpm
  2. #import gettext
  3. from snack import *
  4. from textw.constants import *
  5. from translate import _
  6.  
  7. class PackageGroupWindow:
  8.     def __call__(self, screen, todo, individual):
  9.         # be sure that the headers and comps files have been read.
  10.     todo.getHeaderList()
  11.         todo.getCompsList()
  12.  
  13.         ct = CheckboxTree(height = 10, scroll = 1)
  14.         for comp in todo.comps:
  15.             if not comp.hidden:
  16.                 ct.append(comp.name, comp, comp.selected)
  17.  
  18.         cb = Checkbox (_("Select individual packages"), individual.get ())
  19.  
  20.         bb = ButtonBar (screen, ((_("OK"), "ok"), (_("Back"), "back")))
  21.  
  22.         g = GridForm (screen, _("Package Group Selection"), 1, 3)
  23.         g.add (ct, 0, 0, (0, 0, 0, 1))
  24.         g.add (cb, 0, 1, (0, 0, 0, 1))
  25.         g.add (bb, 0, 2, growx = 1)
  26.  
  27.         result = g.runOnce()
  28.  
  29.         individual.set (cb.selected())
  30.         # turn off all the comps
  31.         for comp in todo.comps:
  32.             if not comp.hidden: comp.unselect(0)
  33.  
  34.         # turn on all the comps we selected
  35.         for comp in ct.getSelection():
  36.             comp.select (1)
  37.  
  38.         rc = bb.buttonPressed (result)
  39.  
  40.         if rc == "back":
  41.             return INSTALL_BACK
  42.         return INSTALL_OK
  43.  
  44. class IndividualPackageWindow:
  45.     def __call__(self, screen, todo, individual):
  46.         if not individual.get():
  47.             return
  48.     todo.getHeaderList()
  49.         todo.getCompsList()
  50.  
  51.         ct = CheckboxTree(height = 10, scroll = 1)
  52.         groups = {}
  53.  
  54.         # go through all the headers and grok out the group names, placing
  55.         # packages in lists in the groups dictionary.
  56.         
  57.         for key in todo.hdList.packages.keys():
  58.             header = todo.hdList.packages[key]
  59.             # don't show this package if it is in the base group
  60.             if not todo.comps["Base"].items.has_key (header):
  61.                 if not groups.has_key (header[rpm.RPMTAG_GROUP]):
  62.                     groups[header[rpm.RPMTAG_GROUP]] = []
  63.                 groups[header[rpm.RPMTAG_GROUP]].append (header)
  64.  
  65.         # now insert the groups into the list, then each group's packages
  66.         # after sorting the list
  67.         def cmpHdrName(first, second):
  68.             if first[rpm.RPMTAG_NAME] < second[rpm.RPMTAG_NAME]:
  69.                 return -1
  70.             elif first[rpm.RPMTAG_NAME] == second[rpm.RPMTAG_NAME]:
  71.                 return 0
  72.             return 1
  73.         
  74.         keys = groups.keys ()
  75.         keys.sort ()
  76.         index = 0
  77.         for key in keys:
  78.             groups[key].sort (cmpHdrName)
  79.             ct.append (key)
  80.             for header in groups[key]:
  81.                 ct.addItem (header[rpm.RPMTAG_NAME], (index, snackArgs["append"]),
  82.                             header, header.selected)
  83.             index = index + 1
  84.                 
  85.         bb = ButtonBar (screen, ((_("OK"), "ok"), (_("Back"), "back")))
  86.  
  87.         g = GridForm (screen, _("Package Group Selection"), 1, 2)
  88.         g.add (ct, 0, 0, (0, 0, 0, 1))
  89.         g.add (bb, 0, 1, growx = 1)
  90.     g.addHotKey("F1")
  91.  
  92.     result = g.run()
  93.     while result == "F1":
  94.         h = ct.getCurrent()
  95.         if type(h) != type(""):
  96.         ButtonChoiceWindow(screen, h['name'], h['description'], 
  97.                     buttons = [ _('Ok') ], x = 5, y = 5)
  98.         result = g.run()
  99.     screen.popWindow()
  100.  
  101.         # turn off all the packages
  102.         for key in todo.hdList.packages.keys ():
  103.             todo.hdList.packages[key].selected = 0
  104.  
  105.         # turn on all the packages we selected
  106.         for package in ct.getSelection ():
  107.             package.selected = 1
  108.  
  109.         rc = bb.buttonPressed (result)
  110.         
  111.         if rc == "back":
  112.             return INSTALL_BACK
  113.  
  114.         return INSTALL_OK
  115.  
  116. class PackageDepWindow:
  117.     def __call__(self, screen, todo):
  118.         deps = todo.verifyDeps ()
  119.         if not deps:
  120.             return INSTALL_NOOP
  121.  
  122.         g = GridForm(screen, _("Package Dependencies"), 1, 5)
  123.         g.add (TextboxReflowed (45, _("Some of the packages you have "
  124.                                       "selected to install require "
  125.                                       "packages you have not selected. If "
  126.                                       "you just select Ok all of those "
  127.                                       "required packages will be "
  128.                                       "installed.")), 0, 0, (0, 0, 0, 1))
  129.         g.add (Label ("%-20s %-20s" % (_("Package"), _("Requirement"))), 0, 1, anchorLeft = 1)
  130.         text = ""
  131.         for name, suggest in deps:
  132.             text = text + "%-20s %-20s\n" % (name, suggest)
  133.         
  134.         if len (deps) > 5:
  135.             scroll = 1
  136.         else:
  137.             scroll = 0
  138.             
  139.         g.add (Textbox (45, 5, text, scroll = scroll), 0, 2, anchorLeft = 1)
  140.         
  141.         cb = Checkbox (_("Install packages to satisfy dependencies"), 1)
  142.         g.add (cb, 0, 3, (0, 1, 0, 1), growx = 1)
  143.         
  144.         bb = ButtonBar (screen, ((_("OK"), "ok"), (_("Back"), "back")))
  145.         g.add (bb, 0, 4, growx = 1)
  146.  
  147.         result = g.runOnce ()
  148.  
  149.         if cb.selected ():
  150.             todo.selectDeps (deps)
  151.         
  152.         rc = bb.buttonPressed (result)
  153.         if rc == string.lower (_("Back")):
  154.             return INSTALL_BACK
  155.         return INSTALL_OK
  156.  
  157.